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xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
};



void dely () {
	int i;
	for (i=0;i<200;i++);
}

void WriteCMD(unsigned char x) {
	RS=0;RW=0;

	P0=x;
	E=1;
	dely();
	E=0;
}


void WriteDATA(unsigned char x) {
	RS=1;RW=0;

	P0=x;
	E=1;
	dely();
	E=0;
}

void LCDinit () {
	/*
	WriteCMD(0x01);
	WriteCMD(0x38);		
	WriteCMD(0x0f);	
	WriteCMD(0x06);	
*/
	WriteCMD(0x3F); // open display
	WriteCMD(0xC0);	// set init line	
	WriteCMD(0xB8);	//x 
	WriteCMD(0x40);	//y
	
}



void main () {


	int x , y , k;
	
	RST=0;RST=1;
	LCDinit();
	
	for (k=0,x=0;x<8;x++) {
		CS1=0;CS2=1;
		WriteCMD(0xB8+x);
		for(y=0;y<64;y++)WriteDATA(dict[k++]);
		
		CS1=1;CS2=0;
		WriteCMD(0xB8+x);
		for(y=0;y<64;y++)WriteDATA(dict[k++]);
		
	}
	
	
	while(1);

}